package thread;

import java.util.concurrent.CountDownLatch;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-10-17
 * Time: 11:22
 */
//编写代码, 基于 CountDownLatch 模拟跑步比赛的过程
public class Demo20 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(10);
        for(int i = 0; i < 10; i++){
            Thread thread = new Thread(() -> {
                try {
                    Thread.sleep(3000);
                    System.out.println("到达终点");
                    latch.countDown();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            thread.start();
            Thread.sleep(1000);
        }
        latch.await();
        System.out.println("比赛结束");
    }
}
